<?php
$redis = new Redis();
$redis->connect('127.0.0.1', 6379);
$redis_name = 'miaosha';
$conn = mysqli_connect('127.0.0.1', 'homestead', 'secret', 'sys');
mysqli_query($conn, 'set names utf8');

while (1) {
    $user = $redis->lPop($redis_name);
    if (!$user || $user == 'nil') {
        sleep(2);
        continue;
    }

    $user_arr = explode('%', $user);

    $res = mysqli_query($conn, "insert into redis_queue (uid, time_stamp) values ('{$user_arr[0]}', '{$user_arr[1]}')");

    if (!$res) {
        $redis->rpush($redis_name, $user);
    }

    sleep(2);
}

mysqli_close($conn);
$reids->close();
